package zero.tech.games.log.service;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import zero.tech.core.data.PageBean;
import zero.tech.core.data.Resp;
import zero.tech.core.data.SimpleUser;
import zero.tech.games.common.Code;
import zero.tech.games.entity.log.LogGoldChange;
import zero.tech.games.entity.log.LogInviteLine;
import zero.tech.games.entity.log.LogPlayback;
import zero.tech.games.entity.log.LogSafetyChange;
import zero.tech.games.entity.log.LogWaterRewardGet;
import zero.tech.games.log.data.LogTradeInfo;
import zero.tech.games.log.data.WaterTeamInfo;
import zero.tech.games.log.data.res.ResBaoxianguiLog;
import zero.tech.games.log.data.res.ResLogGoldChange;
import zero.tech.games.log.data.res.ResLogInviteLine;
import zero.tech.games.log.data.res.ResLogTrade;
import zero.tech.games.log.data.res.ResLogWaterTeam;
import zero.tech.games.log.data.res.ResLogZsTeamWater;
import zero.tech.games.log.data.res.ResPlayback;
import zero.tech.games.log.data.res.ResPlaybackByPage;
import zero.tech.games.log.data.res.ResPlaybackDetail;
import zero.tech.games.log.data.res.ResWaterRewardGet;
import zero.tech.games.log.hot.LogGoldChangeUtil;
import zero.tech.games.log.hot.LogInviteLineUtil;
import zero.tech.games.log.hot.LogPlaybackUtil;
import zero.tech.games.log.hot.LogSafetyChangeUtil;
import zero.tech.games.log.hot.LogTradeUtil;
import zero.tech.games.log.hot.LogWaterRewardGetUtil;
import zero.tech.games.log.hot.LogWaterTeamUtil;
import zero.tech.games.log.service.api.ILogsService;

@Service
public class LogsServiceImpl implements ILogsService{
	@Autowired
	private LogPlaybackUtil logPlaybackUtil;
	@Autowired
	private LogSafetyChangeUtil logSafetyChangeUtil;
	@Autowired
	private LogGoldChangeUtil logGoldChangeUtil;
	@Autowired
	private LogInviteLineUtil logInviteLineUtil;
	@Autowired
	private LogWaterTeamUtil logWaterTeamUtil;
	@Autowired
	private LogWaterRewardGetUtil logWaterRewardGetUtil;
	@Autowired
	private LogTradeUtil logTradeUtil;
	@Override
	public Resp listPlaybackByPage(SimpleUser simpleUser, int club_id, int game_id, Date begin, Date end, int page, int pageLength) {
		int uid=simpleUser.getUid();
		PageBean<ResPlayback> pageBean=logPlaybackUtil.listPlaybackByPage(uid,club_id,game_id,page,pageLength,begin,end);
		ResPlaybackByPage res=new ResPlaybackByPage();
		res.setPageBean(pageBean);
		return Resp.build(Code.OK, "分页获取数据成功",res);
	}
	@Override
	public Resp getPlaybackDetail(SimpleUser simpleUser, int club_id, int game_id, String room_id, String play_code,Date begin,Date end) {
		int uid=simpleUser.getUid();
		LogPlayback logPlayback=logPlaybackUtil.getPlaybackDetail(uid,club_id,game_id,room_id,play_code,begin,end);
		ResPlaybackDetail resPlaybackDetail =new ResPlaybackDetail();
		resPlaybackDetail.setLogPlayback(logPlayback);
		return Resp.build(Code.OK, "获取战绩详情成功",resPlaybackDetail);
	}
	@Override
	public Resp operateBaoxianguiLogs(SimpleUser simpleUser, int club_id, Date begin, Date end, int page,
			int pageLength) {
		int uid=simpleUser.getUid();
		PageBean<LogSafetyChange> pageBean=logSafetyChangeUtil.listLogSafetyChangeByPage(uid,club_id,page,pageLength,begin,end);
		ResBaoxianguiLog res=new ResBaoxianguiLog();
		res.setPageBean(pageBean);
		return Resp.build(Code.OK, "分页获取数据成功",res);
	}
	@Override
	public Resp goldChangeLogs(SimpleUser simpleUser, int club_id, Date begin, Date end, int page, int pageLength,int type) {
		ResLogGoldChange res=new ResLogGoldChange();
		int uid=simpleUser.getUid();
		if(type==1) {
			//出入
			PageBean<LogGoldChange> pageBean=logGoldChangeUtil.goldChangeLogsByChuru(uid,club_id,page,pageLength,begin,end);
			res.setPageBean(pageBean);
		}else if(type==2) {
			//输赢
			PageBean<LogGoldChange> pageBean=logGoldChangeUtil.goldChangeLogsByShuying(uid,club_id,page,pageLength,begin,end);
			res.setPageBean(pageBean);
		}else if(type==3) {
			//茶叶库
			PageBean<LogGoldChange> pageBean=logGoldChangeUtil.goldChangeLogsByChayeku(uid,club_id,page,pageLength,begin,end);
			res.setPageBean(pageBean);
		}else {
			//所有
			PageBean<LogGoldChange> pageBean=logGoldChangeUtil.goldChangeLogs(uid,club_id,page,pageLength,begin,end);
			res.setPageBean(pageBean);
		}
		return Resp.build(Code.OK, "分页获取数据成功",res);
	}
	@Override
	public Resp inviteLineLogs(SimpleUser simpleUser, int club_id,Integer sub_uid, Date begin, Date end, int page, int pageLength) {
		if(sub_uid==null) {
			ResLogInviteLine res=new ResLogInviteLine();
			int uid=simpleUser.getUid();
			PageBean<LogInviteLine> pageBean=logInviteLineUtil.listInviteLineByPage(uid,club_id,page,pageLength,begin,end);
			res.setPageBean(pageBean);
			return Resp.build(Code.OK, "分页获取数据成功",res);
		}else {
			ResLogInviteLine res=new ResLogInviteLine();
			int myuid=simpleUser.getUid();
			PageBean<LogInviteLine> pageBean=logInviteLineUtil.selectInviteLineByPage(myuid,club_id,sub_uid,page,pageLength,begin,end);
			res.setPageBean(pageBean);
			return Resp.build(Code.OK, "分页获取数据成功",res);
		}
	}
	@Override
	public Resp waterTeamLogs(SimpleUser simpleUser, int club_id, Date begin, Date end, int page, int pageLength,int type) {
		ResLogWaterTeam resLogWaterTeam = new ResLogWaterTeam();
		int uid=simpleUser.getUid();
		if(type==1) {
			PageBean<WaterTeamInfo> pageBean=logWaterTeamUtil.listWaterTeamZsByPage(uid,club_id,page,pageLength,begin,end);
			resLogWaterTeam.setPageBean(pageBean);
			return Resp.build(Code.OK, "分页获取数据成功",resLogWaterTeam);	
		}else if(type==2) {
			PageBean<WaterTeamInfo> pageBean=logWaterTeamUtil.listWaterTeamFzsByPage(uid,club_id,page,pageLength,begin,end);
			resLogWaterTeam.setPageBean(pageBean);
			return Resp.build(Code.OK, "分页获取数据成功",resLogWaterTeam);	
		}else {
			PageBean<WaterTeamInfo> pageBean=logWaterTeamUtil.listWaterTeamByPage(uid,club_id,page,pageLength,begin,end);
			resLogWaterTeam.setPageBean(pageBean);
			return Resp.build(Code.OK, "分页获取数据成功",resLogWaterTeam);	
		}
	}
	@Override
	public Resp waterZsTeamLogs(SimpleUser simpleUser, int club_id, Integer other_uid, Date begin, Date end, int page,
			int pageLength) {
		int uid=simpleUser.getUid();
		if(other_uid==null) {
			ResLogZsTeamWater res = logWaterTeamUtil.waterZsTeamLogs(club_id,uid,begin,end,page,pageLength);
			return Resp.build(Code.OK, "分页获取数据成功",res);	
		}else {
			ResLogZsTeamWater res = logWaterTeamUtil.waterZsTeamLogsByUid(club_id,uid,begin,end,page,pageLength,other_uid);
			return Resp.build(Code.OK, "分页获取数据成功",res);	
		}
	}
	@Override
	public Resp waterRewardGetLogs(SimpleUser simpleUser, int club_id, Date begin, Date end, int page, int pageLength) {
		ResWaterRewardGet res = new ResWaterRewardGet();
		int uid=simpleUser.getUid();
		PageBean<LogWaterRewardGet> pageBean=logWaterRewardGetUtil.listWaterRewardGetLogs(uid,club_id,page,pageLength,begin,end);
		res.setPageBean(pageBean);
		return Resp.build(Code.OK, "分页获取数据成功",res);	
	}
	@Override
	public Resp shangxiafenLogs(SimpleUser simpleUser, int club_id, Date begin, Date end, int page, int pageLength,Integer uid) {
		if(uid==null) {
			ResLogTrade resLogTrade = new ResLogTrade();
			int myid=simpleUser.getUid();
			PageBean<LogTradeInfo> pageBean=logTradeUtil.listLogTradeByPage(myid,club_id,page,pageLength,begin,end);
			resLogTrade.setPageBean(pageBean);
			return Resp.build(Code.OK, "分页获取数据成功",resLogTrade);	
		}else {
			ResLogTrade resLogTrade = new ResLogTrade();
			int myid=simpleUser.getUid();
			PageBean<LogTradeInfo> pageBean=logTradeUtil.listLogTradeByPageAndUid(myid,club_id,page,pageLength,begin,end,uid);
			resLogTrade.setPageBean(pageBean);
			return Resp.build(Code.OK, "分页获取数据成功",resLogTrade);	
		}
	}
}
